package jdbc;

import socket.DBUtil;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class LoginDemo {
    public static void main(String[] args) {
        UserInfo inputObject = InputUtil.getInputObject(new UserInfo(), "用户登录", "登录");
        String username = inputObject.getUsername();
        String password = inputObject.getPassword();
        try (Connection conn = DBUtil.getConnection();) {
            Statement statement = conn.createStatement();
//            String sql = "SELECT id,username,password,nickname,age" +
//                    "FROM userinfo" +
//                    "WHERE username=;";
            String sql = "SELECT id,username,password,nickname,age FROM userInfo WHERE username='"+username+"' AND password='"+password+"'";
            ResultSet resultSet = statement.executeQuery(sql);
            if (resultSet.next()){
                System.out.println("登录成功");
            }else {
                System.out.println("登录失败");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
